package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.shopping.dto.CcProductDetailDto;
import com.cskaoyan.shopping.service.IProductService;
import com.cskaoyan.shopping.service.impl.ICartOrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan
 * @date 2022/8/24:14:56
 */
@RestController
public class OrderApiImpl {

    @Autowired
    IProductService productService;

    @Autowired
    ICartOrderServiceImpl iCartOrderService;


    @GetMapping(value = "/rpc/product/detail")
    ServiceCallResponse getProductDetail(@RequestParam("id") Long id) {
        CcProductDetailDto productDetail = productService.getProductDetail(id);
        ServiceCallResponseUtil<CcProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }

    // 订单服务中调用购物车模块中的清除指定购物车的服务
    @DeleteMapping(value = "/rpc/cart/items")
    ClearCartItemServiceResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request){
        iCartOrderService.clearCartItemByUserID(request);
        return new ClearCartItemServiceResponse();
    }
}
